﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsGame1
{
    public class Delay
    {
        float delayDuration;
        public float DelayDuration
        {
            get { return delayDuration; }
            set { delayDuration = value; }
        }
        float countDown = 0;
        bool ok = true;
        
        /// <summary>
        /// Decrement the internal timer and check if the end of the countdown was reached.
        /// </summary>
        /// <param name="t">Game timer</param>
        /// <returns>true if the end has been reached during this update. This will happen only once, Restart need to be called to start a bew cycle.</returns>
        public bool Update(Timer t)
        {
            if (countDown > 0)
            {
                countDown -= t.Delta;
                if (countDown <= 0)
                    ok = true;
                else
                    ok = false;
            }

            return ok;
        }

        public void Restart()
        {
            countDown = delayDuration;
        }

        public Delay(float d)
        {
            delayDuration = d;            
        }
    }
}
